<?php

namespace App\Kuafu\User\Model;

use App\Kuafu\Base\Model\BaseModel;
use App\Kuafu\Base\Model\Traits\KfSoftDeletes;
use App\Kuafu\Base\Model\Traits\KfUid;
use App\Kuafu\Feishu\Model\FsUserModel;
use App\Kuafu\Shop\Model\Shop;
use App\Kuafu\User\Enum\RoleCodeEnum;
use App\Scope\ShopScope;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Schema\Builder;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Collection;
use Tymon\JWTAuth\Contracts\JWTSubject;

class UserUseServiceLogModel extends BaseModel
{
    use KfUid, KfSoftDeletes;

    protected $connection = 'mysql';
    protected $table      = 'user_use_service_logs';
    protected $fillable   = [
        'id',
        'userId',
        'shopId',
        'type'
    ];

    const TYPE_WALLET = 1;

    const TYPE_MAPPING = [
        self::TYPE_WALLET => '钱包',
    ];


    public static function addLog($userId, $shopId, $type): bool
    {
        $model = self::query()->updateOrCreate([
            'userId'       => $userId,
            'shopId'       => $shopId,
            'type'         => $type
        ]);
        $model->updatedAt = time();
        return $model->save();
    }

}
